function result=diffs(p)
    persistent symbols toeval
if isstruct(p)
    syms t y yd mu sigma1 rho1hat
    symbols=[t y yd mu sigma1 rho1hat];
%     mu=t/p.eps/(1-(p.rho)*t+p.rho*p.Ts);
    z1=mu*(y-yd);
    phi1=zeros(2,1); 
    xi1=[phi1;1];
    chi=1/(1-z1^2);
    eta11=chi*(y-yd)^3/sqrt((z1*chi*(y-yd))^2+sigma1^2);
    eta12=z1*chi*mu*(xi1'*xi1)/sqrt(z1^2*chi^2*mu^2*(xi1'*xi1)+sigma1^2);
    eta1=eta11+eta12;
    
%     sigma1=p.sigma1(t);
    alpha1bar=p.k1*(y-yd)*chi+rho1hat*eta1;
    alpha1=-z1*chi*mu*alpha1bar^2/sqrt((z1*chi*mu*alpha1bar)^2+sigma1^2);
    toeval.alpha1_rhohat1=diff(alpha1,rho1hat);
    toeval.alpha1_x1=diff(alpha1,y);
    toeval.alpha1_yd=diff(alpha1,yd);
    toeval.alpha1_mu=diff(alpha1,mu);
    toeval.alpha1_sigma1=diff(alpha1,sigma1);
end
if ~isempty(symbols) && all(size(p)==size(symbols))
    for f=fields(toeval)'
        x=subs(toeval.(f{1}),symbols,p);
        result.(f{1})=double(x);
    end
end
end